package com.hksj.common.log.service;

import com.hksj.common.config.utils.HttpUtils;

import com.hksj.common.log.config.LogProperties;
import org.springframework.stereotype.Service;
import com.hksj.common.log.vo.RequestInfoVO;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zengke
 * @version 1.0
 * @see LogService
 * @since 2024/3/12 8:42
 */
@Service
public class LogService {

    @Resource
    private HttpServletRequest request;

    @Resource
    private LogProperties logProperties;

    /**
     * 获取请求体信息
     * @return {@link RequestInfoVO}
     */
    public RequestInfoVO getRequestInfo(){

        //获取请求的浏览器名称
        String browserName = HttpUtils.getBrowserName(request);

        //获取请求的浏览器版本
        String browserVersion = HttpUtils.getBrowserVersion(request);

        //获取请求的ip地址
        String ipAddr = HttpUtils.getIpAddr(request);

        //获取请求的操作系统名称
        String osName = HttpUtils.getOsName(request);

        //获取请求的地址
        String requestUrl = HttpUtils.getRequestUrl();

        //获取请求的方式
        String requestMethod = HttpUtils.getRequestMethod();

        //返回请求体信息
        return new RequestInfoVO()
                .setBrowserName(browserName)
                .setBrowserVersion(browserVersion)
                .setIpAddr(ipAddr)
                .setOsName(osName)
                .setRequestUrl(requestUrl)
                .setRequestMethod(requestMethod);
    }




}
